home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / workbench / term_4.8 / extras / source / gtlayout-source.lha / LTP_BitMap.c < prev    next >
C/C++ Source or Header  |  1997-05-08  |  3KB  |  147 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1997 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16. /*****************************************************************************/
  17.  
  18. struct FatBitMap
  19. {
  20.     struct BitMap    BitMap;
  21.     LONG            Width;
  22.     LONG            Height;
  23. };
  24.  
  25. /*****************************************************************************/
  26.  
  27. LONG
  28. LTP_GetDepth(struct BitMap *BitMap)
  29. {
  30.     if(V39)
  31.         return((LONG)GetBitMapAttr(BitMap,BMA_DEPTH));
  32.     else
  33.         return(BitMap->Depth);
  34. }
  35.  
  36. VOID
  37. LTP_DeleteBitMap(struct BitMap *BitMap,BOOL Chip)
  38. {
  39.     if(V39 && !Chip)
  40.         FreeBitMap(BitMap);
  41.     else
  42.     {
  43.         if(BitMap)
  44.         {
  45.             struct FatBitMap *Fat;
  46.             LONG i;
  47.  
  48.             Fat = (struct FatBitMap *)BitMap;
  49.  
  50.             if(Fat->Width && Fat->Height)
  51.             {
  52.                 for(i = 0 ; i < BitMap->Depth ; i++)
  53.                     FreeRaster(BitMap->Planes[i],Fat->Width,Fat->Height);
  54.             }
  55.             else
  56.             {
  57.                 for(i = 0 ; i < BitMap->Depth ; i++)
  58.                     FreeVec(BitMap->Planes[i]);
  59.             }
  60.  
  61.             FreeVec(BitMap);
  62.         }
  63.     }
  64. }
  65.  
  66. struct BitMap *
  67. LTP_CreateBitMap(LONG Width,LONG Height,LONG Depth,struct BitMap *Friend,BOOL Chip)
  68. {
  69.     struct BitMap *BitMap;
  70.  
  71.     if(V39 && !Chip)
  72.         BitMap = AllocBitMap(Width,Height,Depth,BMF_MINPLANES,Friend);
  73.     else
  74.     {
  75.         struct FatBitMap *Fat;
  76.  
  77.         if(!(Fat = (struct FatBitMap *)AllocVec(sizeof(struct FatBitMap),MEMF_ANY | MEMF_PUBLIC | MEMF_CLEAR)))
  78.             BitMap = NULL;
  79.         else
  80.         {
  81.             LONG i;
  82.  
  83.             BitMap = (struct BitMap *)Fat;
  84.  
  85.             InitBitMap(BitMap,Depth,Width,Height);
  86.  
  87.             for(i = 0 ; i < Depth ; i++)
  88.             {
  89.                 if(!(BitMap->Planes[i] = AllocRaster(Width,Height)))
  90.                 {
  91.                     LONG j;
  92.  
  93.                     for(j = 0 ; j < i ; j++)
  94.                         FreeRaster(BitMap->Planes[j],Width,Height);
  95.  
  96.                     FreeVec(Fat);
  97.  
  98.                     return(NULL);
  99.                 }
  100.             }
  101.  
  102.             Fat->Width    = Width;
  103.             Fat->Height    = Height;
  104.  
  105.             if(Chip)
  106.             {
  107.                 ULONG Type = MEMF_CHIP;
  108.  
  109.                 for(i = 0 ; i < Depth ; i++)
  110.                     Type &= TypeOfMem(BitMap->Planes[i]);
  111.  
  112.                 if(!(Type & MEMF_CHIP))
  113.                 {
  114.                     LONG PageSize;
  115.  
  116.                     for(i = 0 ; i < Depth ; i++)
  117.                     {
  118.                         FreeRaster(BitMap->Planes[i],Width,Height);
  119.                         BitMap->Planes[i] = NULL;
  120.                     }
  121.  
  122.                     PageSize = BitMap->BytesPerRow * BitMap->Rows;
  123.  
  124.                     for(i = 0 ; i < Depth ; i++)
  125.                     {
  126.                         if(!(BitMap->Planes[i] = AllocVec(PageSize,MEMF_CHIP)))
  127.                         {
  128.                             LONG j;
  129.  
  130.                             for(j = 0 ; j < i ; j++)
  131.                                 FreeVec(BitMap->Planes[j]);
  132.  
  133.                             FreeVec(Fat);
  134.  
  135.                             return(NULL);
  136.                         }
  137.                     }
  138.  
  139.                     Fat->Width = Fat->Height = 0;
  140.                 }
  141.             }
  142.         }
  143.     }
  144.  
  145.     return(BitMap);
  146. }
  147.